home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / Acere (Card Game) / AcereÄ.sit / Acereƒ / WellDeck.cp < prev    next >
Text File  |  1994-08-25  |  7KB  |  269 lines

  1. // ===========================================================================
  2. //    WellDeck.cp                        ⌐1993 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    Class for an object that can draw itself and respond to mouse clicks
  6.  
  7. #ifdef PowerPlant_PCH
  8. #include PowerPlant_PCH
  9. #endif
  10.  
  11. #include "WellDeck.h"
  12. #include "CardDeck.h"
  13. #include "AcereApp.h"
  14. #include "CTextDoc.h"
  15. #include <LDynamicArray.h>
  16. #include <LView.h>
  17. #include <LStream.h>
  18. #include <PP_Messages.h>
  19. #include <UDrawingState.h>
  20.  
  21. extern    CTextDoc    *theDoc;
  22.  
  23. // ---------------------------------------------------------------------------
  24. //        Ñ CreatePaneStream [static]
  25. // ---------------------------------------------------------------------------
  26. //    Return a new Pane object initialized using data from a Stream
  27.  
  28. WellDeck*
  29. WellDeck::CreateWellDeck(
  30.     LStream    *inStream)
  31. {
  32.     return (new WellDeck(inStream));
  33. }
  34.  
  35.  
  36. // ---------------------------------------------------------------------------
  37. //        Ñ WellDeck()
  38. // ---------------------------------------------------------------------------
  39. //    Default Constructor
  40.  
  41. WellDeck::WellDeck()
  42. {
  43.     mPaneID = 0;
  44.     mFrameSize.width = mFrameSize.height = 0;
  45.     mFrameLocation.h = mFrameLocation.v = 0;
  46.     mUserCon = 0;
  47.     
  48.     mFrameBinding.left =
  49.         mFrameBinding.top =
  50.         mFrameBinding.right =
  51.         mFrameBinding.bottom = false;
  52.     
  53.     mVisible = mActive = mEnabled = triState_Latent;
  54.  
  55.     mSuperView = nil;
  56.     
  57.     theDoc->theDeckWells[theDoc->currentDeckWell] = this;
  58.     theDoc->currentDeckWell++;
  59.     itsCard.card = kNoCard;
  60.     itsCard.itsOwner = this;
  61. }
  62.  
  63.  
  64. // ---------------------------------------------------------------------------
  65. //        Ñ WellDeck(const WellDeck&)
  66. // ---------------------------------------------------------------------------
  67. //    Copy Constructor
  68.  
  69. WellDeck::WellDeck(
  70.     const WellDeck    &inOriginal)
  71. {
  72.                                     // Copy members of Original
  73.     mPaneID = inOriginal.mPaneID;
  74.     mFrameSize = inOriginal.mFrameSize;
  75.     mFrameLocation = inOriginal.mFrameLocation;
  76.     mFrameBinding = inOriginal.mFrameBinding;
  77.     mUserCon = inOriginal.mUserCon;
  78.     
  79.     mSuperView = nil;                // Copy is not inside any View
  80.     
  81.                                     // Pane properties. If Original has
  82.                                     //   property ON, Copy is Latent.
  83.     mVisible = inOriginal.mVisible;
  84.     if (mVisible == triState_On) {
  85.         mVisible = triState_Latent;
  86.     }
  87.  
  88.     mActive = inOriginal.mActive;
  89.     if (mActive == triState_On) {
  90.         mActive = triState_Latent;
  91.     }
  92.  
  93.     mEnabled = inOriginal.mEnabled;
  94.     if (mEnabled == triState_On) {
  95.         mEnabled = triState_Latent;
  96.     }
  97.  
  98.     
  99.     theDoc->theDeckWells[theDoc->currentDeckWell] = this;
  100.     theDoc->currentDeckWell++;
  101.     itsCard.card = kNoCard;
  102.     itsCard.itsOwner = this;
  103. }
  104.  
  105.  
  106. // ---------------------------------------------------------------------------
  107. //        Ñ WellDeck(SPaneInfo&)
  108. // ---------------------------------------------------------------------------
  109. //    Construct Pane from data in a struct
  110.  
  111. WellDeck::WellDeck(
  112.     const SPaneInfo    &inPaneInfo)
  113. {
  114.     InitPane(inPaneInfo);
  115. }
  116.  
  117.  
  118. // ---------------------------------------------------------------------------
  119. //        Ñ WellDeck(LStream*)
  120. // ---------------------------------------------------------------------------
  121. //    Construct Pane from data in a Stream
  122.  
  123. WellDeck::WellDeck(
  124.     LStream    *inStream)
  125. {
  126.     SPaneInfo    thePaneInfo;
  127.     inStream->ReadData(&thePaneInfo, sizeof(SPaneInfo));
  128.     InitPane(thePaneInfo);
  129. }
  130.  
  131.  
  132. // ---------------------------------------------------------------------------
  133. //        Ñ InitPane
  134. // ---------------------------------------------------------------------------
  135. //    Initialize Pane from data in a struct
  136.  
  137. void
  138. WellDeck::InitPane(
  139.     const SPaneInfo    &inPaneInfo)
  140. {
  141.     mPaneID = inPaneInfo.paneID;
  142.     mFrameSize.width = inPaneInfo.width;
  143.     mFrameSize.height = inPaneInfo.height;
  144.     mUserCon = inPaneInfo.userCon;
  145.     
  146.     mVisible = triState_Off;
  147.     if (inPaneInfo.visible) {
  148.         mVisible = triState_Latent;
  149.     }
  150.  
  151.     mActive = triState_Latent;
  152.  
  153.     mEnabled = triState_Off;
  154.     if (inPaneInfo.enabled) {
  155.         mEnabled = triState_Latent;
  156.     }
  157.     
  158.     mFrameBinding = inPaneInfo.bindings;
  159.     
  160.     mSuperView = nil;
  161.     
  162.     LView    *theSuperView = inPaneInfo.superView;
  163.     if (theSuperView == Default_SuperView) {
  164.         theSuperView = GetDefaultView();
  165.     }
  166.     PutInside(theSuperView);
  167.     if (theSuperView != nil) {
  168.         PlaceInSuperImageAt(inPaneInfo.left, inPaneInfo.top, false);
  169.         Boolean    expandHoriz = (inPaneInfo.width < 0);
  170.         Boolean    expandVert = (inPaneInfo.height < 0);
  171.         if (expandHoriz || expandVert) {
  172.             theSuperView->ExpandSubPane(this, expandHoriz, expandVert);
  173.         }
  174.     }
  175.     
  176.     theDoc->theDeckWells[theDoc->currentDeckWell] = this;
  177.     theDoc->currentDeckWell++;
  178.     itsCard.card = kNoCard;
  179.     itsCard.itsOwner = this;
  180. }
  181.  
  182.  
  183. // ---------------------------------------------------------------------------
  184. //        Ñ ~WellDeck
  185. // ---------------------------------------------------------------------------
  186. //    Destructor
  187.  
  188. WellDeck::~WellDeck()
  189. {
  190.     PutInside(nil);
  191.     
  192.     if (sLastPaneClicked == this) {
  193.         sLastPaneClicked = nil;
  194.     }
  195. }
  196.  
  197.  
  198. // ---------------------------------------------------------------------------
  199. //        Ñ Draw
  200. // ---------------------------------------------------------------------------
  201. //    Try to draw contents of a Pane
  202. //
  203. //    inSuperDrawRgnH specifies, in Port coordinates, the portion of the
  204. //    Pane's SuperView that needs to be drawn. Specify nil to bypass
  205. //    the intersection test.
  206. //    
  207. //    This is a wrapper function which calls DrawSelf if it is proper for
  208. //    the Pane to draw. This means that:
  209. //        > Pane's Visible property is on
  210. //        > Pane can be focused
  211. //        > Pane's Frame is in QuickDraw space
  212. //        > Pane's Frame intersects inSuperDrawRgnH
  213.  
  214. void    WellDeck::Draw(RgnHandle    inSuperDrawRgnH)
  215. {
  216.     Rect    frame;
  217.     if ( IsVisible()  &&
  218.          FocusDraw()  &&
  219.          CalcPortFrameRect(frame)  &&
  220.          ((inSuperDrawRgnH == nil) || RectInRgn(&frame, inSuperDrawRgnH)) )
  221.     {
  222.         if (itsCard.card == kNoCard)
  223.         {
  224.             EraseRect(&frame);
  225.             FrameRoundRect(&frame, 20, 20);
  226.         }
  227.         else
  228.         {
  229.             theDeck->DrawCard(&itsCard, frame);
  230.             FrameRoundRect(&frame, 20, 20);
  231.         }
  232.     }
  233. }
  234.  
  235. Boolean    WellDeck::CanDropOnEmptySlot(CardStruct *draggedCard)
  236. {
  237.     //    this will be overridden by most subclasses, which is why it's separate
  238.     //    default behavior is that ANY card can be dropped on an empty slot
  239.     
  240.     if (draggedCard->card == 1)        //    it's an ACE
  241.         return (true);
  242.     else
  243.         return (false);
  244. }
  245.  
  246. Boolean    WellDeck::CanDropOnSlot(CardStruct *draggedCard)
  247. {
  248.     //    this will be overridden by most subclasses.
  249.     //    default behavior is that any card can be dropped on any card.
  250.  
  251.     if ((draggedCard->suit == itsCard.suit) && (draggedCard->card == (itsCard.card +1)))
  252.         return (true);
  253.     else
  254.         return (false);
  255. }
  256.  
  257. Boolean    WellDeck::CanRemove(void)            //    can we remove cards from this pile?
  258. {
  259.     return (false);
  260. }
  261.  
  262. void WellDeck::AddCardToWell(CardWell *whichWell, CardStruct *whichCard)
  263. {
  264.     CardWell::AddCardToWell(whichWell, whichCard);
  265.     
  266.     if (whichCard->card == 13)                //    it's a King
  267.         theDoc->CheckVictory();
  268. }
  269.